﻿
using UnityEngine.UI;
using TinyToolKit.UI;
using TinyToolKit;

public enum PlayerState
{
    TakeDamage
}

public class PlayerInfoForm : DefaultUIFormBase
{
    public Slider health;

    private int healthPoint = 100;

    private void OnEnable()
    {
        EventCenter<PlayerState>.Subscribe<int>(PlayerState.TakeDamage, TakeDamage);
    }

    private void TakeDamage(int damage)
    {
        healthPoint -= damage;
        if (healthPoint < 0)
            healthPoint = 0;
        health.value = healthPoint / 100.0f;
    }

    private void OnDisable()
    {
        EventCenter<PlayerState>.Unsubscribe<int>(PlayerState.TakeDamage, TakeDamage);
    }
}
